package com.trade.wzj.service.xiang;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.trade.wzj.dao.xiang.SupplierInfoDao;
import com.trade.wzj.model.xiang.SupplierInfo;

@Service("SupplierInfoService")
public class SupplierInfoimpl implements SupplierInfoService {
	@Resource
	private SupplierInfoDao mapper;

	public SupplierInfoDao getMapper() {
		return mapper;
	}

	public void setMapper(SupplierInfoDao mapper) {
		this.mapper = mapper;
	}
	/*
	 * 供应商基础信息添加
	 * (non-Javadoc)
	 * @see com.trade.wzj.service.xiang.SupplierInfoService#SupplierInfoAdd(com.trade.wzj.model.xiang.SupplierInfo)
	 */
	@Override
	public boolean SupplierInfoAdd(SupplierInfo superlierinfo) throws Exception {
		String name = superlierinfo.getSupplierName();
		SupplierInfo sup = mapper.SelSupplierInfo(name);
		if (superlierinfo.getSupplierName().equals("") && sup != null) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (superlierinfo.getSupplierContacts().equals("")) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (superlierinfo.getSupplierPhone().equals("")) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (superlierinfo.getSupplierAddress().equals("")) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (superlierinfo.getSupplierFax().equals("")) {
			try {
				throw new Exception("不能为空");
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else {
			long result = mapper.SupplierInfoAdd(superlierinfo);
			if (result > 0) {
				System.out.println("messafe" + "该信息已存在，请重新输入");
				return false;
			}
		}
		return true;
	}
	/*
	 * (non-Javadoc)供应商显示
	 * @see com.trade.wzj.service.xiang.SupplierInfoService#SelSupplierInfo(java.lang.String)
	 */
	@Override
	public SupplierInfo SelSupplierInfo(String name) throws Exception{
		SupplierInfo su = null;
		try {
			su = mapper.SelSupplierInfo(name);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return su;
	}

}
